package ui.layer
{
	import adpter.layer.MapLayerAdapter;
	
	import flash.display.Bitmap;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	import ui.common.SpriteObject;
	
	public class MapLayerUI extends SpriteObject
	{
		private var _map:Bitmap;
		
		public function MapLayerUI()
		{
			super();
			init();
		}
		
		private function init():void
		{
			_map = new Bitmap;
			addChild(_map);
		}
		
		protected function get mapLayerAdapter():MapLayerAdapter
		{
			return adapter  as MapLayerAdapter;
		}
		
		override public function create():void
		{
			super.create();
			addEventListener(MouseEvent.CLICK, onClick);
		}
		
		override public function destory():void
		{
			removeEventListener(MouseEvent.CLICK, onClick);
			super.destory();
		}
		
		private function onClick(e:MouseEvent):void
		{
			var pos:Point = new Point(e.localX, e.localY);
			if(mapLayerAdapter)
			{
				mapLayerAdapter.gotoPos(pos);
			}
		}
		
		override public function update():void
		{
			var mapLayer:MapLayerAdapter = adapter as MapLayerAdapter;
			if(mapLayer)
			{
				_map.bitmapData = mapLayer.bmd;
			}
		}
	}
}